package com.dog.basics.api.controller.mtkj;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.api.mtkj.ApiUserAddrAddDto;
import com.dog.basics.bean.dto.api.mtkj.ApiUserAddrEditDto;
import com.dog.basics.bean.dto.api.mtkj.ApiUserAddrPageDto;
import com.dog.basics.bean.vo.api.mtkj.ApiUserAddrVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.security.annotation.Inner;
import com.dog.basics.service.mtkj.IMtUserAddrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

/**
 * <p>
 * 用户配送地址 前端控制器
 * </p>
 *
 * @author wph
 * @since 2020-11-09
 */
@Api(value = "用户配送地址",tags = SwaggerConstants.API_MY)
@RestController
@RequestMapping("/api/useraddr")
@AllArgsConstructor
public class MtUserAddrController {

    private final IMtUserAddrService userAddrService;

    /**
     * 获取用户配送地址列表
     * @param
     * @return
     */
    @GetMapping("/findOne/{userId}")
    @ApiOperation(value = "获取用户配送地址列表", notes = "获取用户配送地址列表",tags = SwaggerConstants.API_USER_ADDR)
    @ApiImplicitParam(value = "用户id", name = "userId", dataType = "Long", required = true)
    @Inner
    public R<IPage<ApiUserAddrVo>> findByUserId(PageParam page , @Valid ApiUserAddrPageDto dto){
        return R.ok(userAddrService.findByUserId(page,dto));
    }

    /**
     * 设置用户默认地址
     * @param userAddrId
     * @return
     * @author hangdy
     */
    @ApiOperation(value = "设置默认用户地址", notes = "设置默认用户地址",tags = SwaggerConstants.API_USER_ADDR)
    @ApiImplicitParam(value = "默认用户地址Id", name = "userAddrId", dataType = "Long", required = true)
    @PutMapping("setDefault/{userAddrId}")
    @Inner
    public R<Boolean> setDefault(@Valid @PathVariable("userAddrId")Long userAddrId){

        return R.ok(userAddrService.setDefault(userAddrId));

    }

    /**
     * 新增用户配送地址
     * @param obj
     * @return
     * @author hangdy
     */

    @ApiOperation(value = "增加用户配送地址", notes = "增加用户配送地址",tags = SwaggerConstants.API_USER_ADDR)
    @PostMapping("/add")
    @Inner
    public R<Boolean> save(@Valid @RequestBody ApiUserAddrAddDto obj) {
        return R.ok(userAddrService.saveUserAddr(obj));
    }

    /**
     * 修改用户配送地址
     * @param obj
     * @return
     * @author hangdy
     */
    @SysLog("修改用户配送地址")
    @ApiOperation(value = "增加用户配送地址", notes = "修改用户配送地址",tags = SwaggerConstants.API_USER_ADDR)
    @PutMapping("/edit")
    @Inner
    public R<Boolean> edit(@Valid @RequestBody ApiUserAddrEditDto obj) {
        return R.ok(userAddrService.editUserAddr(obj));
    }

    /**
     * 删除用户配送地址
     * @param: id
     * @returns 
     * @author hangdy
     * @date: 2020/11/12 15:07
     */
    @ApiOperation(value = "删除用户配送地址", notes = "删除用户配送地址",tags = SwaggerConstants.API_USER_ADDR)
    @ApiImplicitParam(value = "用户配送地址Id", name = "id", dataType = "Long", required = true)
    @DeleteMapping("/delete/{id}")
    @Inner
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.ok(userAddrService.deleteUserAddr(id));
    }
}
